package com.huijie.core.common;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @ClassName IBaseService
 * @Description 基础service实现
 * @Author zyc
 * @Date 2019/1/8 15:27
 * @Version 1.0
 */
public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T> implements IBaseService<T> {

    protected Log log = LogFactory.getLog(getClass());

    @Override
    public boolean insertOrUpdate(T entity) {
        if(null != entity){
            if(StringUtils.checkValNull(entity.getId())){
                return this.insert(entity);
            }else {
                return this.updateById(entity) ;
            }
        }
        return false;
    }

    @Override
    public boolean insert(T entity) {
//        entity.setDeleted(0);
//        entity.setCreateTime(new Date());
//        entity.setCreator(String.valueOf(ContextHelper.getCurrUserId()));
        return super.save(entity);
    }

    @Override
    public boolean updateById(T entity) {
//        entity.setModifier(String.valueOf(ContextHelper.getCurrUserId()));
//        entity.setModifyTime(new Date());
        return super.updateById(entity);
    }

}
